# Figures 3 and 4

#set the working directory here
setwd("")

library(RColorBrewer)
library(cshapes)
# load the IGO membership array:
load("membership-expanded3.rda")

# load the communities data:
load("clubs of clubs data 2.rda")

# load the IGO statistics:
load("igostats5.rda")

colorscheme<-brewer.pal(5, "Spectral")
colorscheme[1]<-"#891012"
names(colorscheme)<-c("Other", "Latin America", "Europe", "Non-regional", "Africa") 

yearlist<-c(1960, 1970, 1980)
png(width=960*2, height=480*2*3, file="Figure 3.png")
par(mfrow=c(3,1))
for (i in 1:length(yearlist)){
	year.current<-yearlist[i]
	x.current<-subset(comm, year==year.current)
	m.current<-cshp(date=as.Date(paste(year.current, "-01-01", sep="")), useGW=FALSE)
	m.current$community<-x.current$comm.name[match(m.current$COWCODE, x.current$country)]
	plot(m.current, col=colorscheme[m.current$community])
	text(0, 80, year.current, cex=4)
	}
dev.off()

yearlist<-c(1990, 2000, 2005)
png(width=960*2, height=480*2*3, file="Figure 4.png")
par(mfrow=c(3,1))
for (i in 1:length(yearlist)){
	year.current<-yearlist[i]
	x.current<-subset(comm, year==year.current)
	m.current<-cshp(date=as.Date(paste(year.current, "-01-01", sep="")), useGW=FALSE)
	m.current$community<-x.current$comm.name[match(m.current$COWCODE, x.current$country)]
	plot(m.current, col=colorscheme[m.current$community])
	text(0, 80, year.current, cex=4)
	}
dev.off()
